package com.db.mongo;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;

public class MongoDBJDBC {
	
	@SuppressWarnings({ "resource" })
	public static void main(String args[]) {
		try {
			// 连接到 mongodb 服务
			MongoClient mongoClient = new MongoClient("localhost", 27017);
			// 连接到数据库,如果指定的数据库不存在，mongo会自动创建数据库
			MongoDatabase mongoDatabase = mongoClient.getDatabase("test");
			System.out.println(String.format("Connect to database [%s] successfully", mongoDatabase.getName()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}